package com.dapeis.core.utils;

import java.util.Map;

import com.ag.utils.DictionarySettingUtils;
import com.fasterxml.jackson.databind.deser.Deserializers.Base;

/**
 * 用户配置表 Title:UserInfoConfig.java UserInfoConfig Description:
 * 
 * @author yuanyong
 * @date 2017年5月9日 下午9:30:07 Email: hzyuanyong@126.com
 *
 */
public class UserInfoConfig {

    /**
     * 脸型LADY
     */
    public static final String FACESHPE_LADY = "cfg.sys.lady.faceshpe";

    /**
     * 脸型MAN
     */
    public static final String FACESHPE_MAN = "cfg.sys.man.faceshpe";

    /**
     * 脸型BASE
     */
    public static final String FACESHPE = "faceshpe";

    /**
     * 肤色LADY
     */
    public static final String COLOROFSKIN_LADY = "cfg.sys.lady.colorofskin";

    /**
     * 肤色MAN
     */
    public static final String COLOROFSKIN_MAN = "cfg.sys.man.colorofskin";

    /**
     * 肤色BASE
     */
    public static final String COLOROFSKIN = "colorofskin";

    /**
     * 体型
     */
    public static final String SIZE_MAN = "cfg.sys.man.size";
    /**
     * 体型LADY
     */
    public static final String SIZE_LADY = "cfg.sys.lady.size";

    /**
     * 体型BASE
     */
    public static final String SIZE = "size";

    /**
     * 解决问题MAN
     */
    public static final String PROBLEM_MAN = "cfg.sys.man.problem";
    /**
     * 解决问题LADY
     */
    public static final String PROBLEM_LADY = "cfg.sys.lady.problem";

    /**
     * 解决问题BASE
     */
    public static final String PROBLEM = "problem";
    /**
     * 风格偏好MAN
     */
    public static final String STYLE_MAN = "cfg.sys.man.style";
    /**
     * 风格偏好LADY
     */
    public static final String STYLE_LADY = "cfg.sys.lady.style";

    /**
     * 解决问题BASE
     */
    public static final String STYLE = "STYL";

    /**
     * 检查解决问题
     * 
     * @param sex
     * @param problem
     * @return
     */
    public static boolean CHECK_PROBLEM(Integer sex, String[] problem) {
	boolean flag = true;
	for (String _problem : problem) {
	    if (StringUtil.isBlank(_problem)) {
		continue;
	    }
	    boolean bl = checkParamSetting(
		    sex == StylistConstants.Sex.LADY ? PROBLEM_LADY
			    : PROBLEM_MAN, _problem);
	    if (!bl) {
		flag = false;
		break;
	    }
	}
	return flag;
    }

    /**
     * 检查风格偏好
     * 
     * @param sex
     * @param style
     * @return
     */
    public static boolean CHECK_STYLE(Integer sex, String[] style) {
	boolean flag = true;
	for (String _style : style) {
	    if (StringUtil.isBlank(_style)) {
		continue;
	    }
	    boolean bl = checkParamSetting(
		    sex == StylistConstants.Sex.LADY ? STYLE_LADY : STYLE_MAN,
		    _style);
	    if (!bl) {
		flag = false;
		break;
	    }
	}
	return flag;
    }

    /**
     * 获取体型参数
     * 
     * @param sex
     * @return
     */
    public static boolean CHECK_SIZE(Integer sex, String bodySize) {
	if (sex == StylistConstants.Sex.LADY)
	    return checkParamSetting(SIZE_LADY, bodySize);
	if (sex == StylistConstants.Sex.MAN)
	    return checkParamSetting(SIZE_MAN, bodySize);
	return false;
    }

    /**
     * 获取肤色参数
     * 
     * @param sex
     * @return
     */
    public static boolean CHECK_COLOROFSKIN(Integer sex, String colorofskin) {
	if (sex == StylistConstants.Sex.LADY)
	    return checkParamSetting(COLOROFSKIN_LADY, colorofskin);
	if (sex == StylistConstants.Sex.MAN)
	    return checkParamSetting(COLOROFSKIN_MAN, colorofskin);
	return false;
    }

    /**
     * 获取脸型参数
     * 
     * @param sex
     * @return
     */
    public static boolean CHECK_FACESHPE(Integer sex, String faceshpe) {
	if (sex == StylistConstants.Sex.LADY)
	    return checkParamSetting(FACESHPE_LADY, faceshpe);
	if (sex == StylistConstants.Sex.MAN)
	    return checkParamSetting(FACESHPE_MAN, faceshpe);
	return false;
    }

    public static String getValue(Integer sex, String baseConfig) {
	if (sex == StylistConstants.Sex.LADY) {
	    if (baseConfig.equals(FACESHPE))
		return FACESHPE_LADY;
	    if (baseConfig.equals(COLOROFSKIN))
		return COLOROFSKIN_LADY;
	    if (baseConfig.equals(SIZE))
		return SIZE_LADY;
	    if (baseConfig.equals(PROBLEM))
		return PROBLEM_LADY;
	    if (baseConfig.equals(STYLE))
		return STYLE_LADY;
	}
	if (sex == StylistConstants.Sex.MAN) {
	    if (baseConfig.equals(FACESHPE))
		return FACESHPE_MAN;
	    if (baseConfig.equals(COLOROFSKIN))
		return COLOROFSKIN_MAN;
	    if (baseConfig.equals(SIZE))
		return SIZE_MAN;
	    if (baseConfig.equals(PROBLEM))
		return PROBLEM_MAN;
	    if (baseConfig.equals(STYLE))
		return STYLE_MAN;
	}
	return null;
    }

    public static boolean checkParamSetting(String variable, String v) {
	Map<String, String> map = DictionarySettingUtils
		.getParameterMap(variable);
	if (map.containsKey(v)) {
	    return true;
	}
	return false;
    }
}
